package com.pinecone.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.pinecone.dao.LiveRoomCommentDao;
import com.pinecone.entity.LiveRoomCommentEntity;
import com.pinecone.service.LiveRoomCommentService;



@Service("liveRoomCommentService")
public class LiveRoomCommentServiceImpl implements LiveRoomCommentService {
	@Autowired
	private LiveRoomCommentDao liveRoomCommentDao;
	@Autowired
    private RedisTemplate redisTemplate;

	@Override
	public LiveRoomCommentEntity queryObject(Long liveRoomCommentId){
		return liveRoomCommentDao.queryObject(liveRoomCommentId);
	}
	
	@Override
	public List<LiveRoomCommentEntity> queryList(Map<String, Object> map){
		return liveRoomCommentDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return liveRoomCommentDao.queryTotal(map);
	}
	
	@Override
	public void save(LiveRoomCommentEntity liveRoomComment){
		liveRoomCommentDao.save(liveRoomComment);
	}
	
	@Override
	public void update(LiveRoomCommentEntity liveRoomComment){
		liveRoomCommentDao.update(liveRoomComment);
	}
	
	@Override
	public void delete(Long liveRoomCommentId){
		liveRoomCommentDao.delete(liveRoomCommentId);
	}
	
	@Override
	public void deleteBatch(Long[] liveRoomCommentIds){
		liveRoomCommentDao.deleteBatch(liveRoomCommentIds);
	}

    //评论点赞
    @Override
    public Long voteComment(String ip, Long commentId) {
        Long res = redisTemplate.opsForSet().add("pineconelive:comment:vote:"+commentId,ip);
        if (res == 0){
            //已经点过赞，则取消点赞
            redisTemplate.opsForSet().remove("pineconelive:comment:vote:"+commentId,ip);
        }
        return res;
    }

    //获取某条评论点赞数
    public Long getCommentVotes(Long commentId){
        return redisTemplate.opsForSet().size("pineconelive:comment:vote:"+commentId);
    }

}
